//
//  WriteApplicationViewController.m
//  jingjing2.0
//
//  Created by apple on 16/5/18.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "WriteApplicationViewController.h"
#import "LocationCityViewController.h"
#import "CompanyApplicationSuccess.h"
#import "CompanyApplicationUnSuccess.h"
@interface WriteApplicationViewController ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate>
{
    UIImageView *_write;//填写申请
    UIImageView *_line1;
    UIImageView *_line2;
    UIImageView *_examin;//审核中
    UIImageView *_pass;//申请通过
    UIButton *_bottomBtn;
    NSMutableArray *_txArr;
    UIView *_bgFlowView;
    CompanyApplicationSuccess *_successView;
    CompanyApplicationUnSuccess *_unsucessView;
    CGFloat _contentOffSetY;
    CGFloat _originalOffSetY;
    NSString *_cityCode;
    UILabel *_lbl3;
}
@property(nonatomic,strong)UITableView *tableView;
@property(nonatomic,strong)NSArray *dataSource;
@property(nonatomic,strong)NSArray *placeHolderArr;
@property(nonatomic,strong)NSMutableDictionary * stringDic;

@end

@implementation WriteApplicationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _txArr=[NSMutableArray array];
    _cityCode=GETCITYCODE;
    self.title=@"填写申请单";
    //表数据
    NSArray *arr1=@[@"选择城市",@"申请企业全称",@"企业联系电话",@"企业邮箱"];
    NSArray *arr2=@[@"姓名",@"联系方式"];
    NSArray *arr3=@[@"企业福利人数",@"申请时长"];
    NSArray *placeHolder1=@[CURRENTCITY,@"填写企业全称",@"企业电座机，确保有人接听",@"确保邮箱地址真实有效"];
    NSArray *placeHolder2=@[@"填写您的姓名",@"填写您的手机号码"];
    NSArray *placeHolder3=@[@"服务人数",@"单位：月"];
    self.dataSource=@[arr1,arr2,arr3];
    self.placeHolderArr=@[placeHolder1,placeHolder2,placeHolder3];
    _stringDic = [NSMutableDictionary dictionaryWithCapacity:7];
    [_stringDic setObject:CURRENTCITY forKey:@"00"];
    self.view.backgroundColor=[UIColor whiteColor];
    self.automaticallyAdjustsScrollViewInsets=NO;
    //创建表
    [self setUpTableView];
    //创建头部进度指示条
    [self setUpTopView];
    //创建底部视图
    [self setUpBottomButton];
    //创建进度视图
    [self setUpIsExaminng];
    //判断申请进度
    [self getProgressOfApplication];
   
}
#pragma mark--获取申请进度请求
-(void)getProgressOfApplication
{
    //http://192.168.1.107:3722/Activity/CompanyWelfareCheck/{UserCode}/{Timestamp}/{Sign}
    NSString *timestamp=[GeneralTool gettimestamp];
    NSDictionary *dic=@{@"UserCode":GETUSERCODE,
                        @"Timestamp":timestamp};
    NSString *sign=[GeneralTool GetSin:dic];
    NSString *urlString=[NSString stringWithFormat:@"Activity/CompanyWelfareCheck/%@/%@/%@",GETUSERCODE,timestamp,sign];
    [RequestTool requestDataWithType:@"get" andUrlString:urlString andParameters:nil andRequestFinished:^(id responses, NSError *error) {
        if ([responses[@"IsSuccess"]integerValue]==1) {
            NSDictionary *dic=responses[@"ReturnObject"];
            switch ([dic[@"FlowStatus"]integerValue]) {
                case 1:
                    return;
                    break;
                case 4:
                {
                    self.title=@"申请审核中";
                    _bgFlowView.hidden=NO;
                    _unsucessView.hidden=YES;
                    _successView.hidden=YES;
                    _tableView.hidden=YES;

                    _examin.image=[UIImage imageNamed:@"apply_being_true"];
                    _line2.image=[UIImage imageNamed:@"apply_top_1"];
                    _line1.image=[UIImage imageNamed:@"apply_top_3"];
                }
                    break;
                case 3:
                {
                    self.title=@"申请已通过";
                    _line1.image=[UIImage imageNamed:@"apply_top_3"];
                     _line2.image=[UIImage imageNamed:@"apply_top_3"];
                    _pass.image=[UIImage imageNamed:@"pay_true"];
                    
                    _examin.image=[UIImage imageNamed:@"apply_being_true"];

                    _bgFlowView.hidden=YES;
                    _unsucessView.hidden=YES;
                    _tableView.hidden=YES;
                    _successView.hidden=NO;
                }
                    break;
                default:
                {
                    self.title=@"申请未通过";
                    _line1.image=[UIImage imageNamed:@"apply_top_3"];
                    _line2.image=[UIImage imageNamed:@"apply_top_4"];
                     _examin.image=[UIImage imageNamed:@"apply_being_true"];
                    _pass.image=[UIImage imageNamed:@"apply_err"];
                    _lbl3.text=@"申请失败";
                    _lbl3.textColor=[UIColor redColor];
                    _unsucessView.hidden=NO;
                    _successView.hidden=YES;
                    _bgFlowView.hidden=YES;
                    _tableView.hidden=YES;

                }

                    break;
            }
        }
    }];
}
#pragma mark--创建审核中视图
-(void)setUpIsExaminng
{
    _bgFlowView=[[UIView alloc]initWithFrame:CGRectMake(0, 64+80, kWidth, kHeight-64-80)];
    _bgFlowView.backgroundColor=[UIColor whiteColor];
    _bgFlowView.hidden=YES;
    [self.view addSubview:_bgFlowView];
    
    _successView=[[CompanyApplicationSuccess alloc]initWithFrame:CGRectMake(0, 64+80, kWidth, kHeight-64-80)];
    _successView.delegate=self;
     _successView.backgroundColor=[UIColor whiteColor];
    _successView.hidden=YES;
    [self.view addSubview:_successView];
    
    _unsucessView=[[CompanyApplicationUnSuccess alloc]initWithFrame:CGRectMake(0, 64+80, kWidth, kHeight-64-80)];
    _unsucessView.delegate=self;
    _unsucessView.backgroundColor=[UIColor whiteColor];
    _unsucessView.hidden=YES;
    [self.view addSubview:_unsucessView];
    
    UIImageView *image=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"apply_being_action"]];
    image.frame=CGRectMake(100, 20, kWidth-200, 100);
    [_bgFlowView addSubview:image];
    
    for (int i=0; i<3; i++) {
        UILabel *lbl=[[UILabel alloc]initWithFrame:CGRectMake(10, i*(30+5)+image.frame.origin.y+100+10, kWidth-20, 30)];
        lbl.textColor=[UIColor darkGrayColor];
        lbl.font=[UIFont systemFontOfSize:15];
        lbl.textAlignment=NSTextAlignmentCenter;
        if (i==0) {
            lbl.text=@"您提交的申请我们已收到～";
        }else if (i==1)
        {
            lbl.text=@"稍后会有净净客服人员与您取得联系";
        }else
        {
            lbl.text=@"请保持您的通讯畅通！";
        }
        [_bgFlowView addSubview:lbl];
    }
    
    UIButton *btn=[[UIButton alloc]initWithFrame:CGRectMake(10, _bgFlowView.frame.size.height-10-40, kWidth-20, 40)];
    [btn setTitle:@"返回首页" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    btn.layer.cornerRadius=4;
    btn.clipsToBounds=YES;
    [btn addTarget:self action:@selector(backToHomeView) forControlEvents:UIControlEventTouchUpInside];
    btn.backgroundColor=BLUECOLOR;
    [_bgFlowView addSubview:btn];
}
-(void)applicationAgain
{
    _pass.image=[UIImage imageNamed:@"pay_false"];
    _lbl3.text=@"申请已通过";
    _lbl3.textColor=[UIColor darkGrayColor];
    _examin.image=[UIImage imageNamed:@"apply_being_false"];
    _line2.image=[UIImage imageNamed:@"apply_top_2"];
    _line1.image=[UIImage imageNamed:@"apply_top_1"];
    _tableView.hidden=NO;
    _bgFlowView.hidden=YES;
    _successView.hidden=YES;
    _unsucessView.hidden=YES;
}
-(void)backToHomeView
{
    NSArray *arr=self.navigationController.viewControllers;
    HomeViewController *home=arr[0];
    [self.navigationController popToViewController:home animated:YES];
}
#pragma mark--底部提交申请按钮
-(void)setUpBottomButton
{
    UIButton *selectedBtn=[[UIButton alloc]initWithFrame:CGRectMake(10, kHeight-40-40, 20, 20)];
    [selectedBtn setBackgroundImage:[UIImage imageNamed:@"update_true_small"] forState:UIControlStateNormal];
    selectedBtn.selected=YES;
    [selectedBtn addTarget:self action:@selector(isAgreen:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:selectedBtn];
    
    UILabel *lbl=[[UILabel alloc]initWithFrame:CGRectMake(selectedBtn.frame.origin.x+20+10, kHeight-40-40, kWidth-10-30, 20)];
    lbl.text=@"我已经同意净净洗衣企业福利条款";
    lbl.textColor=BLUECOLOR;
    lbl.font=[UIFont systemFontOfSize:13];
    [self.view addSubview:lbl];
    
    _bottomBtn=[[UIButton alloc]initWithFrame:CGRectMake(10, kHeight-40-10, kWidth-20, 40)];
    [_bottomBtn setTitle:@"提交申请" forState:UIControlStateNormal];
    [_bottomBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _bottomBtn.layer.cornerRadius=4;
    [_bottomBtn setClipsToBounds:YES];
    _bottomBtn.backgroundColor=[UIColor orangeColor];
    [_bottomBtn addTarget:self action:@selector(SendApplication) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_bottomBtn];
    
}
#pragma mark--是否同意条款
-(void)isAgreen:(UIButton *)btn
{
    if (btn.selected) {
        [btn setBackgroundImage:[UIImage imageNamed:@"update_false_small"] forState:UIControlStateNormal];
        _bottomBtn.backgroundColor=GRAYCOLOR;
        _bottomBtn.enabled=NO;
    }else
    {
       [btn setBackgroundImage:[UIImage imageNamed:@"update_true_small"] forState:UIControlStateNormal];
        _bottomBtn.backgroundColor=[UIColor orangeColor];
        _bottomBtn.enabled=YES;
    }
    btn.selected=!btn.selected;
}
#pragma mark--提交申请
-(void)SendApplication
{
    NSString *message=nil;
    if ([_stringDic[@"00"] length]==0) {
      message=@"企业全称不能为空";
    }else if ([_stringDic[@"01"] length]==0)
    {
        message=@"企业联系电话不能为空";
    }else if ([_stringDic[@"02"] length]==0)
    {
        message=@"企业邮箱不能为空";
    }else if ([_stringDic[@"10"] length]==0)
    {
        message=@"姓名不能为空";
    }else if ([_stringDic[@"11"] length]==0)
    {
        message=@"联系方式不能为空";
    }else if ([_stringDic[@"20"] length]==0)
    {
        message=@"企业福利人数不能为空";
    }else if ([_stringDic[@"21"] length]==0)
    {
        message=@"申请时长不能为空";
    } else if ([GeneralTool valiMobile:_stringDic[@"11"]]!=nil)
    {
        message=[GeneralTool valiMobile:_stringDic[@"11"]];
    }else if (![GeneralTool validateEmail:_stringDic[@"03"]])
    {
        message=@"请填入正确的邮箱格式";
    }else
    {
        //http://192.168.1.107:3722/Activity/CompanyWelfareApply
        //m_CompanyWelfarePara(UserCode,CityCode,CityName,CompanyName,CompanyTel,CompanyEmail,LinkMan,LinkMobile,PeopleNumber,MonthCount,Timestamp,Sign)
       // NSString *timeStamp=[GeneralTool gettimestamp];
        NSString *timeStamp=[GeneralTool gettimestamp];
    
        NSDictionary *signDic=@{@"UserCode":GETUSERCODE,
                                @"CityCode":_cityCode,
                                @"CityName":_stringDic[@"00"],
                                @"CompanyName":_stringDic[@"01"],
                                @"CompanyTel":_stringDic[@"02"],
                                @"CompanyEmail":_stringDic[@"03"],
                                @"LinkMan":_stringDic[@"10"],
                                @"LinkMobile":_stringDic[@"11"],
                                @"PeopleNumber":_stringDic[@"20"],
                                @"MonthCount":_stringDic[@"21"],
                                @"Timestamp":timeStamp};
        NSString *sign=[GeneralTool GetSin:signDic];
        NSDictionary *requestDic=@{@"UserCode":GETUSERCODE,
                                   @"CityCode":_cityCode,
                                   @"CityName":_stringDic[@"00"],
                                @"CompanyName":_stringDic[@"01"],
                                @"CompanyTel":_stringDic[@"02"],
                                @"CompanyEmail":_stringDic[@"03"],
                                @"LinkMan":_stringDic[@"10"],
                                @"LinkMobile":_stringDic[@"11"],
                                @"PeopleNumber":_stringDic[@"20"],
                                @"MonthCount":_stringDic[@"21"],
                                @"Timestamp":timeStamp,
                                @"Sign":sign};
        NSDictionary *dic=@{@"m_CompanyWelfarePara":requestDic};
        [RequestTool requestDataWithType:@"post" andUrlString:@"Activity/CompanyWelfareApply" andParameters:dic andRequestFinished:^(id responses, NSError *error) {
            if (error)
            {
                [MBProgressHUD showError:@"连接服务器失败，请检查网络"];
            }
            if ([responses[@"IsSuccess"]integerValue]==1)
            {
                if ([responses[@"ReturnObject"]isEqualToString:@"申请提交成功"]) {
                    _bgFlowView.hidden=NO;
                    NSUserDefaults *data=[NSUserDefaults standardUserDefaults];
                    [data setObject:_stringDic[@"03"] forKey:@"email"];
                    [data setObject:_stringDic[@"01"] forKey:@"companyName"];
                    [data synchronize];
                }
            }else
            {
                [MBProgressHUD showError:responses[@"ReturnObject"]];
            }
        }];
        
    }
    if (message) {
         [ZMTool showAlertWithDifferentVersioninWhichViewController:self withTitle:nil andMessage:message andSureTitle:nil andCancleTitle:@"知道了" isDelegate:NO andSureBlock:nil andCancleBlock:nil];
    }
}
#pragma mark--头部进度指示条视图
-(void)setUpTopView
{
    CGFloat interval=(kWidth-90-60)/2.0;
    _write=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"write_apply_true"]];
    _write.frame=CGRectMake(30, 74, 30, 30);
    [self.view addSubview:_write];
    
    UILabel *lbl=[[UILabel alloc]initWithFrame:CGRectMake(_write.frame.origin.x-15, _write.frame.origin.y+30+5, 80, 20)];
    lbl.text=@"填写申请单";
    lbl.font=[UIFont systemFontOfSize:13];
    lbl.textColor=[UIColor darkGrayColor];
    [self.view addSubview:lbl];
    
    _line1=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"apply_top_1"]];
    _line1.frame=CGRectMake(_write.frame.origin.x+30, 89, interval, 5);
    [self.view addSubview:_line1];
    
    _examin=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"apply_being_false"]];
    _examin.frame=CGRectMake(_line1.frame.origin.x+interval, 74, 30, 30);
    [self.view addSubview:_examin];
    
    UILabel *lbl2=[[UILabel alloc]initWithFrame:CGRectMake(_examin.frame.origin.x-15, _examin.frame.origin.y+30+5, 80, 20)];
    lbl2.text=@"申请审核中";
    lbl2.font=[UIFont systemFontOfSize:13];
    lbl2.textColor=[UIColor darkGrayColor];
    [self.view addSubview:lbl2];

    _line2=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"apply_top_2"]];
    _line2.frame=CGRectMake(_examin.frame.origin.x+30, 89, interval, 5);
    [self.view addSubview:_line2];
    
    _pass=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"apply_result_false"]];
    _pass.frame=CGRectMake(_line2.frame.origin.x+interval, 74, 30, 30);
    [self.view addSubview:_pass];
    
    _lbl3=[[UILabel alloc]initWithFrame:CGRectMake(_pass.frame.origin.x-15, _pass.frame.origin.y+30+5, 80, 20)];
    _lbl3.text=@"申请已通过";
    _lbl3.font=[UIFont systemFontOfSize:13];
    _lbl3.textColor=[UIColor darkGrayColor];
    [self.view addSubview:_lbl3];

}
#pragma mark--表
-(void)setUpTableView
{
    _tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 64+80, kWidth, kHeight-64-80-90)];
    _tableView.delegate=self;
    _tableView.dataSource=self;
    _tableView.contentSize=CGSizeMake(kWidth, kHeight*2);
    [self.view addSubview:_tableView];
    
    UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(txEndEditing)];
    [_tableView addGestureRecognizer:tap];
}
//键盘下去时让表在滑回去
-(void)txEndEditing
{
     [_tableView setContentOffset:CGPointMake(0,_tableView.contentOffset.y+( _contentOffSetY-_originalOffSetY)) animated:YES];
    [self.view endEditing:YES];
}
//记录滑动的位置
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    _originalOffSetY=scrollView.contentOffset.y;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 30;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.dataSource.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSArray *arr=self.dataSource[section];
    return arr.count;
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    if (section==0) {
        return @"企业信息";
    }else if (section==1)
    {
        return @"申请人信息";
    }else
    {
        return @"其他信息";
    }
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"reuse"];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"reuse"];
        UITextField *tx=[[UITextField alloc]initWithFrame:CGRectMake(150, 0, kWidth-150, 44)];
        [tx resignFirstResponder];
        tx.font=[UIFont systemFontOfSize:14];
        tx.delegate=self;
        tx.tag=111;
        tx.returnKeyType=UIReturnKeyNext;
        [cell addSubview:tx];
        
    }
    cell.textLabel.text=self.dataSource[indexPath.section][indexPath.row];
    UITextField * tx = (UITextField *)[cell viewWithTag:111];
    tx.placeholder=self.placeHolderArr[indexPath.section][indexPath.row];
    tx.keyboardType = UIKeyboardTypeDefault;
    tx.text = nil;
    tx.enabled = YES;
    //能取到，就赋值 
    if ([_stringDic objectForKey:[NSString stringWithFormat:@"%zd%zd",indexPath.section,indexPath.row]])
    {
        tx.text = [_stringDic objectForKey:[NSString stringWithFormat:@"%zd%zd",indexPath.section,indexPath.row]];
    }
    //解决重用
    for (UIView *view in cell.subviews) {
        if ([view isKindOfClass:[UIButton class]]) {
            [view removeFromSuperview];
        }
    }
    cell.accessoryView=nil;
    //重新赋值
    UIImageView *image=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"public_right"]];
    image.frame=CGRectMake(kWidth-30, 10, 20, 20);
    CustomButton *control=[[CustomButton alloc]initWithFrame:tx.frame];
    [control addTarget:self action:@selector(goToChooseCity:) forControlEvents:UIControlEventTouchUpInside];
    control.backgroundColor=[UIColor clearColor];
    control.title=nil;
    if (indexPath.section==0) {
        if (indexPath.row==0) {
            tx.text=CURRENTCITY;
            tx.enabled=NO;
            control.title=@"city";
            [cell addSubview:control];
            cell.accessoryView=image;
        }
        if (indexPath.row==2) {
            tx.keyboardType=UIKeyboardTypeNumberPad;
        }
    }
    if (indexPath.section==1)
    {
        if (indexPath.row==1)
        {
            tx.keyboardType=UIKeyboardTypeNumberPad;
        }
    }
    if (indexPath.section==2)
    {
        if (indexPath.row==0)
        {
            tx.keyboardType=UIKeyboardTypeNumberPad;
        }
        if (indexPath.row==1) {
            tx.returnKeyType=UIReturnKeyDone;
            tx.enabled=NO;
            control.title=@"days";
            [cell addSubview:control];
            cell.accessoryView=image;
            
        }
    }
    return cell;
}

-(void)goToChooseCity:(CustomButton *)btn
{
    if ([btn.title isEqualToString:@"city"]) {
        LocationCityViewController *location=[[LocationCityViewController alloc]init];
        location.hidesBottomBarWhenPushed=YES;
        location.currentCity=CURRENTCITY;
        location.passCityBlock=^(NSString *cityName,NSString *cityCode)
        {
            UITableViewCell *cell=[_tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
            NSArray *Arr=cell.subviews;
            for (UIView *view in Arr) {
                if ([view isKindOfClass:[UITextField class]]) {
                    UITextField *tx=(UITextField *)view;
                    tx.text=cityName;
                    [_stringDic setObject:cityName forKey:@"00"];
                    _cityCode=cityCode;
                }
            }
        };
        [self.navigationController pushViewController:location animated:YES];
    }else
    {
        UITextField *tx=nil;
        UITableViewCell *cell=[_tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:2]];
        NSArray *Arr=cell.subviews;
        for (UIView *view in Arr) {
            if ([view isKindOfClass:[UITextField class]]) {
                tx=(UITextField *)view;
            }
        }

        [ZMTool showActionSheetWithDifferentVersioninWhichViewController:self withTitle:@"请选择月份" andMessage:nil andSureTitleOne:@"三个月" andSureTitleTwo:@"六个月" andSureTitleThree:@"十二个月" andCancleTitle:nil isDelegate:YES andSureBlockOne:^(UIAlertAction *action) {
            tx.text=@"三个月";
            [_stringDic setObject:@"3" forKey:@"21"];
        } andSureBlockTwo:^(UIAlertAction *action) {
            tx.text=@"六个月";
            [_stringDic setObject:@"6" forKey:@"21"];

        } andSureBlockThree:^(UIAlertAction *action) {
            tx.text=@"十二个月";
        } andCancleBlock:nil];
        [_stringDic setObject:@"12" forKey:@"21"];
        
    }
}
#pragma mark--下一个输入框成为第一响应
-(BOOL)textFieldShouldReturn:(UITextField *)textField;
{
    UITableViewCell *cell=(UITableViewCell *)textField.superview;
    NSIndexPath *indexPath=[_tableView indexPathForCell:cell];
    NSString *string=[NSString stringWithFormat:@"%ld%ld",(long)indexPath.section,(long)indexPath.row];
    NSIndexPath *index=nil;
    if ([string isEqualToString:@"00"]) {
        index=[NSIndexPath indexPathForRow:1 inSection:0];
    }else if ([string isEqualToString:@"01"])
    {
        index=[NSIndexPath indexPathForRow:2 inSection:0];
    }else if ([string isEqualToString:@"02"])
    {
        index=[NSIndexPath indexPathForRow:3 inSection:0];
    }else if ([string isEqualToString:@"03"])
    {
        index=[NSIndexPath indexPathForRow:0 inSection:1];
    }else if ([string isEqualToString:@"10"])
    {
        index=[NSIndexPath indexPathForRow:1 inSection:1];
    }else if ([string isEqualToString:@"11"])
    {
        index=[NSIndexPath indexPathForRow:0 inSection:2];
    }else if ([string isEqualToString:@"20"])
    {
        index=[NSIndexPath indexPathForRow:1 inSection:2];
    }
    UITableViewCell *lastCell=[_tableView cellForRowAtIndexPath:index];
    NSArray *subViewArr=lastCell.subviews;
    for (UIView *view in subViewArr) {
        if ([view isKindOfClass:[UITextField class]]) {
            [view becomeFirstResponder];
        }
    }
    [_tableView scrollToRowAtIndexPath:index atScrollPosition:UITableViewScrollPositionTop animated:YES];
    _contentOffSetY=_tableView.contentOffset.y;
    return YES;
}
#pragma mrak--表滑动
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    UITableViewCell *cell=(UITableViewCell *)textField.superview;
    NSIndexPath *indexPath=[_tableView indexPathForCell:cell];
    [_tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
    _contentOffSetY=_tableView.contentOffset.y;
    return YES;
}
#pragma mark--记录输入框内容
-(void)textFieldDidEndEditing:(UITextField *)textField
{
    UITableViewCell * cell = (UITableViewCell*)textField.superview;
    NSIndexPath * indexPath = [_tableView indexPathForCell:cell];
    [_stringDic setObject:textField.text forKey:[NSString stringWithFormat:@"%zd%zd",indexPath.section,indexPath.row]];
   
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [GeneralTool hideTabBar];
}
-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [GeneralTool showTabBar];
}

-(void)dealloc
{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
